package ace.cmp.i18n.api;

import java.util.Locale;

/**
 * @author caspar
 * @date 2023/8/10 14:19 扩展 {@link org.springframework.context.MessageSource}
 */
public interface AceMessageSource {

  /**
   * Try to resolve the message. Return default message if no message was found.
   *
   * @param code           the message code to look up, e.g. 'calculator.noRateSet'.
   *                       MessageSource users are encouraged to base message names on qualified class
   *                       or package names, avoiding potential conflicts and ensuring maximum clarity.
   * @param args           an array of arguments that will be filled in for params within
   *                       the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
   *                       or {@code null} if none
   * @param defaultMessage a default message to return if the lookup fails
   * @return the resolved message if the lookup was successful, otherwise
   * the default message passed as a parameter (which may be {@code null})
   * @see #getMessage(MessageSourceResolvable, Locale)
   * @see java.text.MessageFormat
   */
  String getMessage(String code, Object[] args, String defaultMessage);

  /**
   * Try to resolve the message. Treat as an error if the message can't be found.
   *
   * @param code the message code to look up, e.g. 'calculator.noRateSet'.
   *             MessageSource users are encouraged to base message names on qualified class
   *             or package names, avoiding potential conflicts and ensuring maximum clarity.
   * @param args an array of arguments that will be filled in for params within
   *             the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
   *             or {@code null} if none
   * @return the resolved message (never {@code null})
   * @throws NoSuchMessageException if no corresponding message was found
   * @see #getMessage(MessageSourceResolvable, Locale)
   * @see java.text.MessageFormat
   */
  String getMessage(String code, Object[] args);
}
